<?php

class gonggongAction extends CommonAction
{
    public function index()
    {

        $username=I('session.username','');
        if(empty($username))
            redirect("Index/logout/");
        $this->username=$username;
        $this->display();
    }

    public  function modify()
    {
        $userid = $_SESSION["userid"];
        $employeeTable=M("employee");
        $employee=$employeeTable->find($userid);

        $this->employee=$employee;
        $this->display();
    }

    public function  changeren()
    {

        $employee = D('employee');
        $data = $employee->create();
        if (!$data) $this->error($employee->getError());

        if (empty($data["password"]))
        {
            unset($data["password"]);
        }

        $count = $employee->save($data);
        if ($count > 0) {
            $this->assign("waitSecond", 1);
            $this->assign("jumpUrl", U("gonggong/modify"));
            $this->success("修改成功");
        } else {
            $this->error("修改失败或未修改");
        }
    }


    public function modipass()
    {

        $oldpass=I("post.oldpass");
        $newpass=I("post.newpass");
        $newpass1=I("post.newpass1");

        //dump($_POST);

        if($newpass!==$newpass1)
        {
            $this->error("两次密码不一样");
        }

        $employe=M("employee");
        $userid=I('session.userid');
        $data["id"]=$userid;
        $username=I('session.username','');
        if(empty($userid))
        {
            redirect("Index/logout/",2,"登录超时");
        }


        $condition["username"]=$username;
        $condition["password"]=md5($oldpass);
        $olddata=$employe->where($condition)->find();
        if(!$olddata)
        {
            $this->error("旧密码错误");
        }







        $data["password"]=md5($newpass);

        $result=$employe->save($data);
        if ($result) {
            $this->assign("waitSecond", 1);
            $this->assign("jumpUrl", U("Index/logout"));
            $this->success("修改成功,请从新登录");
        } else {
            $this->error("修改失败");
        }

    }



}